package persentation.presentStudent;

import java.awt.Font;
import java.util.ArrayList;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.BevelBorder;
import javax.swing.table.DefaultTableModel;

import vo.chooseCourseVO.ChooseCourseVO;
import vo.informVO.StudentInformVO;
import businesslogic.informBl.InformController;

import javax.swing.ListSelectionModel;

import org.omg.CORBA.PRIVATE_MEMBER;

public class InformPanel extends JPanel {
	private InformController informController;
	private JTable table;
	private ArrayList<StudentInformVO> studentInformVOs;
	
	/**
	 * Create the panel.
	 */
	public InformPanel(InformController informController) {

		this.informController=informController;
		setSize(800, 643);
		setLayout(null);
		
		studentInformVOs=informController.getStudentInform();

		
		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(33, 10, 692, 441);
		this.add(scrollPane);
		
		table = new JTable();
		table.setEnabled(false);
		table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		table.setFont(new Font("微软雅黑", Font.PLAIN, 20));
		table.setModel(new DefaultTableModel(
			new Object[][] {
				{null,null}
			},
			new String[] {
					 "序号","通知内容"
			}
		) 
		{
			Class[] columnTypes = new Class[] {
				String.class, String.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		});
		table.setBounds(119, 424, 262, 143);
		scrollPane.setViewportView(table);
		table.getColumnModel().getColumn(0).setPreferredWidth(20);
		table.getColumnModel().getColumn(1).setPreferredWidth(100);
		

		table.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		fillTable();
	}
	
        public void fillTable(){
		
		DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
		table.getColumnModel().getColumn(0).setPreferredWidth(20);
		table.getColumnModel().getColumn(1).setPreferredWidth(100);
		 tableModel.setRowCount(0);
		 int i=1;
		 for(StudentInformVO studentInformVO:studentInformVOs){
			 String[] contentStrings=new String[2];
			 contentStrings[0]=i+"";
			contentStrings[1]=studentInformVO.getMessage();
				i++;
			 tableModel.addRow(contentStrings);
			 table.invalidate();
			 table.updateUI();
	      }
	}
}
